<?php
/**
 * Created by PhpStorm.
 * User: 69548
 * Date: 2018/8/20
 * Time: 15:14
 */

namespace app\wap\controller;

use  app\wap\model\Collection as M;


class Collection extends Basewap
{

    public function index(){

        $post= request()->post();
//        $goods_id=input('goods_id');
//        $collection_types=input('collection_types');
        $m=new M();
//        $member= db('member')->where('wechat_openid',$openId)->find();
        $map['member_id']=$post['member_id'];
        $map['goods_id']=$post['goods_id'];
//        'member_id',$member['member_id'])->where('goods_id',$goods_id
        $cl= $m
            ->where($map)
//            ->where('goods_id',$goods_id)
//            ->where('collection_types',$collection_types)
            ->select();
        $shu=[];

        if (!empty($cl)){

            $cl=  $m->where($map)->delete();

            if ($cl==true){
                $shu=[
                    'code'=>0,
                    'msg'=>'取消收藏成功',
                ];
            }else{
                $shu=[
                    'code'=>0,
                    'msg'=>'取消收藏失败',
                ];
            }

        }else{
            $map['collection_types']=!empty($post['collection_types'])?$post['collection_types']:1;
            $map['creattime']=time();
            $cl=  $m->insert($map);
            if ($cl==true){
                $shu=[
                    'code'=>0,
                    'msg'=>'收藏成功',
                ];
            }else{
                $shu=[
                    'code'=>0,
                    'msg'=>'收藏失败',
                ];
            }

        }
        return json_encode($shu);
    }




}